<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<!-- 新 Bootstrap4 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">

<link rel="stylesheet" href="../../../../common/css/bootstrap-table.min.css">
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>

<script src="../../../../common/js/bootstrap-table.min.js"></script>
<script src="../../../../common/js/bootstrap-table-zh-CN.min.js"></script>

<!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单，包含了 popper.min.js -->
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>

<!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>

<link href="../../../../static/css/jquery.dataTables.min.css" rel="stylesheet">
<link href="../../../../static/css/style.css" rel="stylesheet">

<body>

    <table id="tableShow" class="table">

    </table>



    <!-- 模态框 -->
    <div class="modal fade" id="myModal">
        <div class="modal-dialog modal-xl">
            <div class="modal-content">

                <!-- 模态框头部 -->
                <div class="modal-header">
                    <h4 class="modal-title">入库审批</h4>
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                </div>

                <!-- 模态框主体 -->
                <div class="modal-body">

                    <div style="margin-left: 10%">
                        <button class='btn btn-danger'  onclick="UpdateAudit(this)"data-dismiss="modal">不通过</button>
                        <button class='btn btn-primary' onclick="UpdateAudit(this)"data-dismiss="modal">通过</button>
                    </div>
                    <div class="shadow" style="width: 80%;height: 30%;margin-top: 5px;margin-left: 10%;padding: 10px">
                        <div class="text-center">
                            <h2>入库申请单</h2>
                        </div>

                        <div class="form-group row">

                            <label for="gatherId" class="col-sm-2 col-form-label">申请单编号:</label>
                            <div class="col-sm-6">
                                <input class="form-control" readonly type="text" id="gatherId">
                            </div>
                        </div>
                        <div class="form-group row">

                            <label for="storer" class="col-sm-2 col-form-label">入库人:</label>
                            <div class="col-sm-3">
                                <input class="form-control" readonly type="text" id="storer">
                            </div>
                            <div class="col-2"></div>
                            <label for="reason" class="col-sm-2 col-form-label">入库理由:</label>
                            <div class="col-sm-3">
                                <input class="form-control" readonly type="text" id="reason">
                            </div>
                        </div>

                        <div>

                            <table class="table">
                                <tbody>
                                <tr style="background-color: gray">
                                    <th>产品名称</th>
                                    <th>产品编号</th>
                                    <th>描述</th>
                                    <th>数量</th>
                                    <th>单位</th>
                                    <th>成本单价</th>
                                    <th>小记</th>
                                </tr>
                                </tbody>
                                <tbody id="tbodyShow2">

                                </tbody>

                            </table>

                        </div>

                        <div class="form-group row">

                            <label for="amountSum" class="col-sm-2 col-form-label"> 总件数：</label>
                            <div class="col-sm-3">
                                <input class="form-control" readonly type="text" id="amountSum">
                            </div>
                            <div class="col-2"></div>
                            <label for="costPriceSum" class="col-sm-2 col-form-label">总金额；</label>
                            <div class="col-sm-3">
                                <input class="form-control" readonly type="text" id="costPriceSum">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="amountSum" class="col-sm-2 col-form-label" > 登记人：</label>
                            <div class="col-sm-3">
                                <input class="form-control" readonly type="text" id="register">
                            </div>
                            <div class="col-2"></div>
                            <label for="costPriceSum" readonly class="col-sm-2 col-form-label">登记时间；</label>
                            <div class="col-sm-3">
                                <input class="form-control" readonly type="text" id="registerTime">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="checker" class="col-sm-2 col-form-label" > 审核人：</label>
                            <div class="col-sm-3">
                                <input class="form-control" readonly type="text" id="checker">
                            </div>
                            <div class="col-2"></div>
                            <label for="checkTime" readonly class="col-sm-2 col-form-label">审核时间；</label>
                            <div class="col-sm-3">
                                <input class="form-control" readonly type="text" id="checkTime">
                            </div>
                        </div>

<!--                        <div class="form-group row">-->
<!--                            <label for="amountSum" readonly class="col-sm-2 col-form-label"> 备注：</label>-->
<!--                            <div class="col-sm-6">-->
<!--                                <textarea id="remark" readonly style="width: 200px"></textarea>-->
<!--                            </div>-->

<!--                        </div>-->
                        <div class="col" style="margin-bottom: 10px">
                            <label for="amountSum" class="col-sm-2 col-form-label"> 备注：</label>
                            <textarea class="form-control" rows="4"  id="remark"
                                      style="height: 115px;border-color: #c7c7c7;resize:none"></textarea>
                        </div>


                    </div>

                </div>

                <!-- 模态框底部 -->
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                </div>

            </div>
        </div>
    </div>

<script>
    $(function () {
        query()
        f()
    })

    //获取当前用户名
    function f() {
        $.ajax({
            type:"POST",
            url:"/user.action",
            success:function (data) {
              $("#checker").val(data.loginId)
            }
        })
    }

    function query() {
        $("#tableShow").bootstrapTable({
            method:"get",
            contentType:"application/json;charset=utf-8",
            url:"/querySGatherXiaotan.action",
            pageNumber:"1",
            pageSize:"5",
            height: 600,
            striped:true,
            pagination:true,
            sidePagination: "server",
            pageList: [3,5,7,9],
            queryParams:function(parts){
                return{
                    currentPage:(parts.offset/parts.limit)+1,
                    pageSize:parts.limit
                }
            },
            columns:[
                {title:"申请单编号",field:"gatherId"},
                // {title:"入库理由",field:"reason"},
                {title:"入库理由",field:"reason",formatter:function (value,row,index) {
                        let but=value=="R001-1"?"生产入库":value=="R001-2"?"库存初始":value=="R001-3"
                                                ?"赠送":value=="R001-4"?"内部归还":"其他归还"

                        return but;
                    }},
                {title:"登记时间",field:"registerTime"},
                {title:"总件数",field:"amountSum"},
                {title:"总金额",field:"costPriceSum"},
                {title:"操作",field:"id",formatter:function (value,row,index) {
                        let but="<button class='btn btn-outline-warning' onclick='audit("+value+")' class='btn btn-primary' data-toggle='modal' data-target='#myModal'>审核</button>";
                        return but;
                    }}
            ]
        })
    }
    function audit(data) {
        // alert(data)
        $.ajax({
            type:"POST",
            url:"/queryBYIDXiaotan.action?id="+data,
            success:function (SGBean) {
                // alert(SGBean)
                // console.log(SGBean)
                add(SGBean)
            }
        })
    }

    function add(sG) {
        $("#gatherId").val(sG.gatherId)
        $("#storer").val(sG.storer)
        $("#reason").val(sG.reason=="R001-1"?"生产入库":sG.reason=="R001-2"?"库存初始":sG.reason=="R001-3"
            ?"赠送":sG.reason=="R001-4"?"内部归还":"其他归还")
        $("#amountSum").val(sG.amountSum)
        $("#costPriceSum").val(sG.costPriceSum)
        $("#register").val(sG.register)
        $("#registerTime").val(sG.registerTime)
        $("#remark").val(sG.remark)

        $("#checkTime").val(new Date().toLocaleString())
        for (let i=0;i<sG.list.length;i++){
            $("#tbodyShow2").append("<tr>" +
                "<td>"+sG.list[i].productName+"</td>" +
                "<td>"+sG.list[i].productId+"</td>" +
                "<td>"+sG.list[i].productDescribe+"</td>" +
                "<td>"+sG.list[i].amount+"</td>" +
                "<td>"+sG.list[i].amountUnit+"</td>" +
                "<td>"+sG.list[i].costPrice+"</td>" +
                "<td>"+sG.list[i].subtotal+"</td>" +
                "</tr>")
        }
    }

    //审核结果提交
    function UpdateAudit(data) {
        let s="S001-2";

        if(data.innerText=="通过"){
            s="S001-1";
        }

        let bean={
            gatherId:$("#gatherId").val(),
            checker:$("#checker").val(),
            checkTime:$("#checkTime").val(),
            checkTag:s,
        }
        $.ajax({
            type:"POST",
            url:"/UpdateAuditXiatoan.action",
            contentType:"application/json;charset=utf-8",
            data:JSON.stringify(bean),
            success:function () {
                alert("审核提交成功！")
                $("#tableShow").bootstrapTable('refresh')
            }
        })
    }

</script>
</body>
</html>